import { post } from '@/core/utils/http';
import type { Response } from '@/core/models';

/**  获取购物车列表 */
export const queryCartList = (data : any) : Promise<Response<any>> => {
	return post('Api/Cart/GetList', {
		data,
	}, true);
}

/**  单个商品删除 */
export const deleteGoodsSingle = (data : any) : Promise<Response<any>> => {
	return post('Api/Cart/DoDelete', {
		data,
	}, true);
}

/**  多个商品删除 */
export const deleteGoodsSome = (data : any) : Promise<Response<any>> => {
	return post('Api/Cart/DoDeleteByIds', {
		data,
	}, true);
}

/**  获取购物车数量和商品总价格 */
export const queryCartNumAndMoney = () : Promise<Response<{ count : number, money : number }>> => {
	return post('Api/User/GetCartNumberAndMoney', {}, true);
}

/**  添加购物车 */
export const queryAddCart = (data : any) : Promise<Response<any>> => {
	return post('Api/Cart/AddCart', {
		data,
	}, true);
}

/**  获取购物车数量 */
export const queryCartNum = () : Promise<Response<number>> => {
	return post('Api/User/GetCartNumber', {}, true);
}

/** 根据购物车已有数据获取能够使用的优惠券 */
export const queryCartCoupon = (data : any) : Promise<Response<any>> => {
	return post('Api/Cart/GetCartAvailableCoupon', {
		data,
	}, true);
}

/** 移除购物车 */
export const queryRemoveCart = (data : any) : Promise<Response<any>> => {
	return post('Api/Cart/DoDelete', {
		data,
	}, true);
}

export const setCartProductNum = (productId : number, nums : number) => {
	return post('api/Cart/SetCartNum', { data: { id: productId, nums } })
}